package com.imooc.spark.streaming.outputOperations

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * @description
  * @author yuyon26@126.com
  * @date 2018/10/24 23:20
  */
object ForeachRDD {
  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
    val ssc = new StreamingContext(sparkConf, Seconds(5))
    ssc.sparkContext.setLogLevel("ERROR")

    val lines = ssc.socketTextStream("192.168.31.30", 9999)
    val mapLines = lines.flatMap(_.split(" "))

    mapLines.foreachRDD(rdd => {
      rdd.foreachPartition(partition => {
        partition.foreach(record => {
          println(record)
        })
      })
    })

    ssc.start()
    ssc.awaitTermination()
  }
}
